/**
 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package de.hsmannheim.pepa.patientenportal.apanwep.model;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.BaseModel;
import com.liferay.portal.model.impl.BaseModelImpl;

import de.hsmannheim.pepa.patientenportal.apanwep.service.ClpSerializer;
import de.hsmannheim.pepa.patientenportal.apanwep.service.chronikLocalServiceUtil;

import java.io.Serializable;

import java.lang.reflect.Method;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Cedric Nana
 */
public class chronikClp extends BaseModelImpl<chronik> implements chronik {
	public chronikClp() {
	}

	@Override
	public Class<?> getModelClass() {
		return chronik.class;
	}

	@Override
	public String getModelClassName() {
		return chronik.class.getName();
	}

	@Override
	public long getPrimaryKey() {
		return _chronik_id;
	}

	@Override
	public void setPrimaryKey(long primaryKey) {
		setChronik_id(primaryKey);
	}

	@Override
	public Serializable getPrimaryKeyObj() {
		return _chronik_id;
	}

	@Override
	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("chronik_id", getChronik_id());
		attributes.put("datetime", getDatetime());
		attributes.put("message", getMessage());
		attributes.put("object", getObject());
		attributes.put("participant", getParticipant());
		attributes.put("user_id", getUser_id());
		attributes.put("event_date_time_at", getEvent_date_time_at());
		attributes.put("event_date_time_down", getEvent_date_time_down());
		attributes.put("event_action", getEvent_action());
		attributes.put("enable", getEnable());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long chronik_id = (Long)attributes.get("chronik_id");

		if (chronik_id != null) {
			setChronik_id(chronik_id);
		}

		String datetime = (String)attributes.get("datetime");

		if (datetime != null) {
			setDatetime(datetime);
		}

		String message = (String)attributes.get("message");

		if (message != null) {
			setMessage(message);
		}

		String object = (String)attributes.get("object");

		if (object != null) {
			setObject(object);
		}

		String participant = (String)attributes.get("participant");

		if (participant != null) {
			setParticipant(participant);
		}

		Long user_id = (Long)attributes.get("user_id");

		if (user_id != null) {
			setUser_id(user_id);
		}

		String event_date_time_at = (String)attributes.get("event_date_time_at");

		if (event_date_time_at != null) {
			setEvent_date_time_at(event_date_time_at);
		}

		String event_date_time_down = (String)attributes.get(
				"event_date_time_down");

		if (event_date_time_down != null) {
			setEvent_date_time_down(event_date_time_down);
		}

		String event_action = (String)attributes.get("event_action");

		if (event_action != null) {
			setEvent_action(event_action);
		}

		Long enable = (Long)attributes.get("enable");

		if (enable != null) {
			setEnable(enable);
		}
	}

	@Override
	public long getChronik_id() {
		return _chronik_id;
	}

	@Override
	public void setChronik_id(long chronik_id) {
		_chronik_id = chronik_id;

		if (_chronikRemoteModel != null) {
			try {
				Class<?> clazz = _chronikRemoteModel.getClass();

				Method method = clazz.getMethod("setChronik_id", long.class);

				method.invoke(_chronikRemoteModel, chronik_id);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public String getDatetime() {
		return _datetime;
	}

	@Override
	public void setDatetime(String datetime) {
		_datetime = datetime;

		if (_chronikRemoteModel != null) {
			try {
				Class<?> clazz = _chronikRemoteModel.getClass();

				Method method = clazz.getMethod("setDatetime", String.class);

				method.invoke(_chronikRemoteModel, datetime);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public String getMessage() {
		return _message;
	}

	@Override
	public void setMessage(String message) {
		_message = message;

		if (_chronikRemoteModel != null) {
			try {
				Class<?> clazz = _chronikRemoteModel.getClass();

				Method method = clazz.getMethod("setMessage", String.class);

				method.invoke(_chronikRemoteModel, message);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public String getObject() {
		return _object;
	}

	@Override
	public void setObject(String object) {
		_object = object;

		if (_chronikRemoteModel != null) {
			try {
				Class<?> clazz = _chronikRemoteModel.getClass();

				Method method = clazz.getMethod("setObject", String.class);

				method.invoke(_chronikRemoteModel, object);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public String getParticipant() {
		return _participant;
	}

	@Override
	public void setParticipant(String participant) {
		_participant = participant;

		if (_chronikRemoteModel != null) {
			try {
				Class<?> clazz = _chronikRemoteModel.getClass();

				Method method = clazz.getMethod("setParticipant", String.class);

				method.invoke(_chronikRemoteModel, participant);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public long getUser_id() {
		return _user_id;
	}

	@Override
	public void setUser_id(long user_id) {
		_user_id = user_id;

		if (_chronikRemoteModel != null) {
			try {
				Class<?> clazz = _chronikRemoteModel.getClass();

				Method method = clazz.getMethod("setUser_id", long.class);

				method.invoke(_chronikRemoteModel, user_id);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public String getEvent_date_time_at() {
		return _event_date_time_at;
	}

	@Override
	public void setEvent_date_time_at(String event_date_time_at) {
		_event_date_time_at = event_date_time_at;

		if (_chronikRemoteModel != null) {
			try {
				Class<?> clazz = _chronikRemoteModel.getClass();

				Method method = clazz.getMethod("setEvent_date_time_at",
						String.class);

				method.invoke(_chronikRemoteModel, event_date_time_at);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public String getEvent_date_time_down() {
		return _event_date_time_down;
	}

	@Override
	public void setEvent_date_time_down(String event_date_time_down) {
		_event_date_time_down = event_date_time_down;

		if (_chronikRemoteModel != null) {
			try {
				Class<?> clazz = _chronikRemoteModel.getClass();

				Method method = clazz.getMethod("setEvent_date_time_down",
						String.class);

				method.invoke(_chronikRemoteModel, event_date_time_down);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public String getEvent_action() {
		return _event_action;
	}

	@Override
	public void setEvent_action(String event_action) {
		_event_action = event_action;

		if (_chronikRemoteModel != null) {
			try {
				Class<?> clazz = _chronikRemoteModel.getClass();

				Method method = clazz.getMethod("setEvent_action", String.class);

				method.invoke(_chronikRemoteModel, event_action);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public long getEnable() {
		return _enable;
	}

	@Override
	public void setEnable(long enable) {
		_enable = enable;

		if (_chronikRemoteModel != null) {
			try {
				Class<?> clazz = _chronikRemoteModel.getClass();

				Method method = clazz.getMethod("setEnable", long.class);

				method.invoke(_chronikRemoteModel, enable);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	public BaseModel<?> getchronikRemoteModel() {
		return _chronikRemoteModel;
	}

	public void setchronikRemoteModel(BaseModel<?> chronikRemoteModel) {
		_chronikRemoteModel = chronikRemoteModel;
	}

	public Object invokeOnRemoteModel(String methodName,
		Class<?>[] parameterTypes, Object[] parameterValues)
		throws Exception {
		Object[] remoteParameterValues = new Object[parameterValues.length];

		for (int i = 0; i < parameterValues.length; i++) {
			if (parameterValues[i] != null) {
				remoteParameterValues[i] = ClpSerializer.translateInput(parameterValues[i]);
			}
		}

		Class<?> remoteModelClass = _chronikRemoteModel.getClass();

		ClassLoader remoteModelClassLoader = remoteModelClass.getClassLoader();

		Class<?>[] remoteParameterTypes = new Class[parameterTypes.length];

		for (int i = 0; i < parameterTypes.length; i++) {
			if (parameterTypes[i].isPrimitive()) {
				remoteParameterTypes[i] = parameterTypes[i];
			}
			else {
				String parameterTypeName = parameterTypes[i].getName();

				remoteParameterTypes[i] = remoteModelClassLoader.loadClass(parameterTypeName);
			}
		}

		Method method = remoteModelClass.getMethod(methodName,
				remoteParameterTypes);

		Object returnValue = method.invoke(_chronikRemoteModel,
				remoteParameterValues);

		if (returnValue != null) {
			returnValue = ClpSerializer.translateOutput(returnValue);
		}

		return returnValue;
	}

	@Override
	public void persist() throws SystemException {
		if (this.isNew()) {
			chronikLocalServiceUtil.addchronik(this);
		}
		else {
			chronikLocalServiceUtil.updatechronik(this);
		}
	}

	@Override
	public chronik toEscapedModel() {
		return (chronik)ProxyUtil.newProxyInstance(chronik.class.getClassLoader(),
			new Class[] { chronik.class }, new AutoEscapeBeanHandler(this));
	}

	@Override
	public Object clone() {
		chronikClp clone = new chronikClp();

		clone.setChronik_id(getChronik_id());
		clone.setDatetime(getDatetime());
		clone.setMessage(getMessage());
		clone.setObject(getObject());
		clone.setParticipant(getParticipant());
		clone.setUser_id(getUser_id());
		clone.setEvent_date_time_at(getEvent_date_time_at());
		clone.setEvent_date_time_down(getEvent_date_time_down());
		clone.setEvent_action(getEvent_action());
		clone.setEnable(getEnable());

		return clone;
	}

	@Override
	public int compareTo(chronik chronik) {
		long primaryKey = chronik.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}

		if (!(obj instanceof chronikClp)) {
			return false;
		}

		chronikClp chronik = (chronikClp)obj;

		long primaryKey = chronik.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(21);

		sb.append("{chronik_id=");
		sb.append(getChronik_id());
		sb.append(", datetime=");
		sb.append(getDatetime());
		sb.append(", message=");
		sb.append(getMessage());
		sb.append(", object=");
		sb.append(getObject());
		sb.append(", participant=");
		sb.append(getParticipant());
		sb.append(", user_id=");
		sb.append(getUser_id());
		sb.append(", event_date_time_at=");
		sb.append(getEvent_date_time_at());
		sb.append(", event_date_time_down=");
		sb.append(getEvent_date_time_down());
		sb.append(", event_action=");
		sb.append(getEvent_action());
		sb.append(", enable=");
		sb.append(getEnable());
		sb.append("}");

		return sb.toString();
	}

	@Override
	public String toXmlString() {
		StringBundler sb = new StringBundler(34);

		sb.append("<model><model-name>");
		sb.append("de.hsmannheim.pepa.patientenportal.apanwep.model.chronik");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>chronik_id</column-name><column-value><![CDATA[");
		sb.append(getChronik_id());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>datetime</column-name><column-value><![CDATA[");
		sb.append(getDatetime());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>message</column-name><column-value><![CDATA[");
		sb.append(getMessage());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>object</column-name><column-value><![CDATA[");
		sb.append(getObject());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>participant</column-name><column-value><![CDATA[");
		sb.append(getParticipant());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>user_id</column-name><column-value><![CDATA[");
		sb.append(getUser_id());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>event_date_time_at</column-name><column-value><![CDATA[");
		sb.append(getEvent_date_time_at());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>event_date_time_down</column-name><column-value><![CDATA[");
		sb.append(getEvent_date_time_down());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>event_action</column-name><column-value><![CDATA[");
		sb.append(getEvent_action());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>enable</column-name><column-value><![CDATA[");
		sb.append(getEnable());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private long _chronik_id;
	private String _datetime;
	private String _message;
	private String _object;
	private String _participant;
	private long _user_id;
	private String _event_date_time_at;
	private String _event_date_time_down;
	private String _event_action;
	private long _enable;
	private BaseModel<?> _chronikRemoteModel;
}